/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pruebas;

import org.neo4j.cluster.ClusterSettings;
import org.neo4j.cypher.ExecutionEngine;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.HighlyAvailableGraphDatabaseFactory;
import org.neo4j.helpers.Settings;
import org.neo4j.kernel.ha.HaSettings;
import org.neo4j.kernel.impl.util.StringLogger;

/**
 *
 * @author pablo
 */
public class TestNeo4JClusterMaster extends AbstractNeo4jCluster{
   protected final static String DB_LOCATION = "http://192.168.1.109:7474/db/data/";
	protected final static String SERVER_ID = "1";

	public static void main(String[] args) throws InterruptedException {
		new TestNeo4JClusterMaster();
	}
//newHighlyAvailableDatabaseBuilder(DB_LOCATION);
	public TestNeo4JClusterMaster() throws InterruptedException {
		GraphDatabaseBuilder builder = new HighlyAvailableGraphDatabaseFactory()
                        .newEmbeddedDatabaseBuilder(DB_LOCATION);
               
		builder.setConfig(ClusterSettings.server_id, SERVER_ID);
		builder.setConfig(HaSettings.ha_server, "192.168.1.101:6001");
		builder.setConfig(HaSettings.slave_only, Settings.FALSE);
		builder.setConfig(ClusterSettings.cluster_server, "192.168.1.101:5001");
		builder.setConfig(ClusterSettings.initial_hosts, "192.168.1.101:5001,192.168.1.102:5001");

		graphDb = builder.newGraphDatabase();
              
		engine = new ExecutionEngine(graphDb, StringLogger.SYSTEM);
		         // executeQuery("CREATE (n:Animal { name : 'Andres', title : 'Developer' })");
                while (true) {
			Thread.sleep(1000);
			executeQuery("MATCH (n) RETURN n LIMIT 100");
		}
	} 
}
